#include <cstdio>
#include <algorithm>
#include <set>
using namespace std;
int main(void){
    //freopen("data.txt","r",stdin);
    int a,b;
    int c=1;
	while(~scanf("%d%d",&a,&b) && (a!=-1 && b!=-1)){
        if(a==0 && b==0){
            printf("Case %d is a tree.\n",c++);
            continue;
        }
        set<int> p;
        p.insert(a);
        p.insert(b);
        int m=1;
        while(scanf("%d%d",&a,&b) && (a || b)){
            p.insert(a);
            p.insert(b);
            m++;
        }
        if(p.size()-m!=1){
            printf("Case %d is not a tree.\n",c++);
        }
        else{
            printf("Case %d is a tree.\n",c++);
        }
    }
    return 0;
}
